﻿using SaaS.Model.Dto.Systems;
using SaaS.Model.Enums;
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using XCore.Domain.Entities;

namespace SaaS.Model.Entity.Auths
{
    /// <summary>
    /// 总管理员后台登录用户表
    /// </summary>
    [Table("Sys_Admins")]
    public class SystemAdmin : IEntity<int>, IHasCreationTime
    {
        [Column("AdminId"), Key]
        public int Id { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        [StringLength(32)]
        [Required]
        public string UserName { get; set; }
        /// <summary>
        /// 姓名
        /// </summary>
        [StringLength(32)]
        [Required]
        public string Name { get; set; }
        /// <summary>
        /// 角色Id，关联权限
        /// </summary>
        public int RoleId { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        [StringLength(128)]
        [Required]
        public string Password { get; set; }
        /// <summary>
        /// 是否默认管理员
        /// </summary>
        public bool IsDefault { get; set; }
        /// <summary>
        /// 头像
        /// </summary>
        [StringLength(128)]
        public string Avatar { get; set; }
        /// <summary>
        /// 用户状态
        /// </summary>
        public UserStatus Status { get; set; }
        public DateTime CreationTime { get; set; }

        public static implicit operator SystemAdminModel(SystemAdmin admin)
        {
            return new SystemAdminModel()
            {
                AdminId = admin.Id,
                CreationTime = admin.CreationTime,
                IsDefault = admin.IsDefault,
                Name = admin.Name,
                RoleId = admin.RoleId,
                UserName = admin.UserName,
                Status = admin.Status,
                Password = admin.Password,
                Avatar = admin.Avatar
            };
        }
    }
}
